package alipay.openplatform.edu.campus.jiuye.api.authentication;/**
 * Created by zhangyang on 26/8/2016.
 */

import alipay.openplatform.edu.campus.jiuye.api.utils.ContextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 前端认证拦截
 *
 * @author zhangyang
 * @create 2016-08-26
 */
public class AdminAuthenticationFilter extends HandlerInterceptorAdapter {
    private static final Logger logger = LoggerFactory.getLogger(AdminAuthenticationFilter.class);

    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {
        HandlerMethod method = (HandlerMethod) handler;

   /*     boolean apiLoginRequired = AnnotationUtils.findAnnotation(method.getBean()
                .getClass(), FrontApiLoginRequest.class) != null
                || method.getMethodAnnotation(FrontApiLoginRequest.class) != null;
*/
        String userId =ContextUtils.getUserId(request);

        /*if (apiLoginRequired&&userInfo==null){
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter pw = response.getWriter();
            String result=JSON.toJSONString(ApiResult.build("401","未登录"));
            pw.write(result);
            pw.flush();
            response.flushBuffer();
            return false;
        }else if (userInfo!=null){
            Operater operater=new Operater();
            //operater.setOperaterId(userInfo.getUid());
            operater.setOperaterType(Operater.OperaterType.USER);
            ThreadContextUtils.setOperaterToThreadLocal(operater);
        }*/
        return true;
    }



}
